package view;

import controller.WindowController;
import java.awt.Dimension;
import java.awt.Rectangle;
import javax.swing.JPanel;
import javax.swing.Scrollable;
import javax.swing.SwingConstants;

/**
 * Settings to allow expect scrolling behaviour for InstrumentListPanel and TrackListPanel.
 * Rather than scrolling one pixel at a time, an entire sequence is scrolled of
 * multiples of them when needed.
 */
public abstract class ScrollableListPanel extends JPanel implements Scrollable {

	@Override
	public Dimension getPreferredScrollableViewportSize() {
		return new Dimension(0,0);
	}

	@Override
	public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
		return TrackPanel.DEFAULT_HEIGHT*2;
	}

	@Override
	public boolean getScrollableTracksViewportHeight() {
		return false;
	}

	@Override
	public boolean getScrollableTracksViewportWidth() {
		return false;
	}

	@Override
	public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
		if(orientation == SwingConstants.VERTICAL) {
			//If a complete sequence is not exposed, make sure it align it back.
			int diff = visibleRect.y % TrackPanel.DEFAULT_HEIGHT;
			if(diff > 0) {
				return direction > 0 ? TrackPanel.DEFAULT_HEIGHT - diff : diff;
			}
			return TrackPanel.DEFAULT_HEIGHT;
		}

		return WindowController.MIN_SIZE.width/2;
	}
}
